<?php
class Reflect
{
    private $s;

    public function __construct($s)
    {
        $this->s=$s;
    }

    private function func1($s)
    {
        return "$s ".date('Y-m-d H:i:s');
    }

    public function hello($s, $i)
    {
        print self::func1("hello $s")."\n";
    }

    function __destruct()
    {
    }
}

$r=new Reflect('hello');
$arr=get_class_methods($r);    
print_r($arr);

$cls=new ReflectionClass('Reflect');
$methods=$cls->getMethods();
foreach($methods as $m)
{
    print $m->getName().":";
    if($m->isConstructor())
        print " construct";
    if($m->isDestructor())
        print " destruct ";
    if($m->isPublic())
        print " public";
    print "\n";
}
print "-----------------------------------\n";

$m='hello';
if(is_callable(get_class($r)."::".$m))
{
    $r->$m("OK", 100);
}
print "-----------------------------------\n";

$m=new ReflectionMethod($r, 'hello');
if($m->isPublic())
{
    $m->invoke($r, "OK", 100);
}
print "-----------------------------------\n";

$cls=new ReflectionClass('Reflect');
$methods=$cls->getMethods();
foreach($methods as $method)
{
    if($method->isPublic())
    {
        print $method->getName()."\n";
        $arr=$method->getParameters();
        foreach($arr as $p)
        {
            print $p->getName()."\n";
        }
    }
}
print "-----------------------------------\n";
?>
